package com.server.common.code.utils;


import com.server.common.code.http.HttpState;

import java.util.HashMap;

public class AjaxResult extends HashMap<String,Object>{

    /** 状态码 */
    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    public AjaxResult(int code, String msg){
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public AjaxResult(Object data, int code, String msg){
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(DATA_TAG, data);
    }


    /***
     * 请求成功-返回数据和消息和成功码
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult success(Object data,int code,String msg){
        return new AjaxResult(data,code,msg);
    }

    /***
     * 请求成功-返回数据和消息
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult success(Object data,String msg){
        return new AjaxResult(data, HttpState.OK,msg);
    }

    /***
     * 请求成功-返回数据
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult successData(Object data){
        return new AjaxResult(data, HttpState.OK,HttpState.OK_STR);
    }

    /***
     * 请求成功-返回数据
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult successMsg(Object data){
        return new AjaxResult(data, HttpState.OK,HttpState.OK_STR);
    }

    /***
     * 请求成功-无参
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult success(){
        return new AjaxResult(HttpState.OK,HttpState.OK_STR);
    }

    /***
     * 请求错误-返回数据和信息
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult error(Object data,String msg){
        return new AjaxResult(data,HttpState.ERROR,msg);
    }

    /***
     * 请求错误-返回数据和信息
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult error(int code,String msg){
        return new AjaxResult(code,msg);
    }

    /***
     * 请求错误-返回信息
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult error(String msg){
        return new AjaxResult(HttpState.ERROR,msg);
    }

    /***
     * 请求错误-无参
     * @author LXC
     * @date 2022/3/13 18:32
     */
    public static AjaxResult error(){
        return new AjaxResult(HttpState.ERROR,HttpState.ERROR_STR);
    }



}
